package com.etime.shycourse.services.ad.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.dao.AdPlaceMapper;
import com.etime.shycourse.pojo.AdPlace;
import com.etime.shycourse.services.ad.interfaces.AdPlacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 广告位置管理业务逻辑层接口实现
 */
@Service
public class AdPlacesServiceImpl implements AdPlacesService {
    @Autowired
    private AdPlaceMapper adPlaceMapper;

    /**
     * 添加广告位置
     * @param adplace
     * @return
     */
    @Override
    public Integer insertAdPlace(AdPlace adplace) {
        return adPlaceMapper.insert(adplace);
    }

    /**
     * 修改广告位置
     * @param adplace
     * @return
     */
    @Override
    public Integer updataAdPlace(AdPlace adplace) {
        return adPlaceMapper.updateById(adplace);
    }

    /**
     * 查询广告位置
     * @param adplace
     * @return
     */
    @Override
    public List<AdPlace> selectAdplace(AdPlace adplace) {
        QueryWrapper<AdPlace> wrapper= new QueryWrapper<>();
        if(adplace!=null && adplace.getPlacename()!=null){
            wrapper.eq("placename",adplace.getPlacename());
        }
        return adPlaceMapper.selectList(wrapper);
    }

    @Override
    public Page<AdPlace> selectAdplacePage(AdPlace adplace, Long pageNum, Long pageSize) {
        Page<AdPlace> page= new Page<>(pageNum,pageSize);
        QueryWrapper<AdPlace> wrapper = new QueryWrapper<>();

        return adPlaceMapper.selectPage(page,wrapper);
    }

    @Override
    public AdPlace selectAdplaceById(Integer placeid) {
        return adPlaceMapper.selectById(placeid);
    }
}
